//
//  ISProtectLogoCollectionViewCell.m
//  iPhoneSafety
//
//  Created by dlon 2018/12/31.
//  Copyright © 2018年 com.li.ding. All rights reserved.
//

#import "ISProtectLogoCollectionViewCell.h"
#import "NWLazyProperty.h"
#import <Masonry/Masonry.h>

@interface ISProtectLogoCollectionViewCell()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) CADisplayLink *displayLink;
@end

@implementation ISProtectLogoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self.contentView addSubview:self.imgView];
        [self.contentView addSubview:self.titleLabel];
        
        [self.imgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(220.f, 220.f));
            make.center.equalTo(self.contentView);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.imgView);
        }];
        [self starTime];
    }
    return self;
}

#pragma mark - priavte
- (void)updateProcess {
    self.imgView.transform = CGAffineTransformRotate(self.imgView.transform, 2 * M_PI/60.f);
}

- (void)stopTimer {
    [self.displayLink invalidate];
    self.displayLink = nil;
}

- (void)starTime {
    [self stopTimer];
    self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateProcess)];
    [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}

- (void)dealloc {
   [self stopTimer];
}

#pragma mark - set & get
NWLazyPropertyWithInit(UIImageView, imgView, {
    _imgView.image = [UIImage imageNamed:@"img_protect_banner"];
    _imgView.contentMode = UIViewContentModeScaleAspectFit;
})

NWLazyPropertyWithInit(UILabel, titleLabel, {
    _titleLabel.font = [UIFont systemFontOfSize:20.f];
    _titleLabel.textColor = [UIColor nw_colorWithHex:0x0991F4];
    _titleLabel.text = @"正在保护中";
})

@end
